#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/27 11:32
from typing import List

from sqlmodel import Session, select

import common
from api.entity import Person


class PersonService(object):
    @staticmethod
    def create_person(persons: List[Person], session: Session, autocommit: bool = True):
        try:
            session.add_all(persons)
            if autocommit:
                session.commit()
        except Exception as e:
            common.get_logger().error('创建当事人报错：{}', e)
            session.rollback()

    @staticmethod
    def list_person(case_id: int, session: Session):
        return session.exec(select(Person).where(Person.case_id == case_id)).all()
